﻿using Entities;
using Logger4Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities;

namespace Hubberly
{
   public class WorldInfoData
   {
      //////////////////////////////////////////////////////////////////////////
      //
      public WorldInfoData(World world)
      {
         world_ = world;
      }

      //////////////////////////////////////////////////////////////////////////
      //
      private WorldInfoCity getInfoCity(City city)
      {
         WorldInfoCity infoCity = null;
         try
         {
            if (!cities_.TryGetValue(city, out infoCity))
            {
               cities_[city] = infoCity = new WorldInfoCity(city);
            }
         }
         catch (System.Exception ex)
         {
            logger_.exception(ex);
         }
         return infoCity;
      }

      //////////////////////////////////////////////////////////////////////////
      //
      public void setPopulation(City city, int population)
      {
         try
         {
            getInfoCity(city).population = population;
         }
         catch (System.Exception ex)
         {
            logger_.exception(ex);
         }
      }

      //////////////////////////////////////////////////////////////////////////
      //
      public void setFactory(City city, Factory factory, int count)
      {
         try
         {
            getInfoCity(city).setFactory(factory, count);
         }
         catch (System.Exception ex)
         {
            logger_.exception(ex);
         }
      }

      //////////////////////////////////////////////////////////////////////////
      //
      public void setConvoy(string name, List<City> ports)
      {
         try
         {
            if (!convoys_.ContainsKey(name))
            {
               convoys_.Add(name, ports);
            }
            convoys_[name] = ports;
         }
         catch (System.Exception ex)
         {
            logger_.exception(ex);
         }
      }

      //////////////////////////////////////////////////////////////////////////
      //
      public List<WorldInfoCity> infoCities
      {
         get { return cities_.Values.ToList(); }
      }

      //////////////////////////////////////////////////////////////////////////
      //
      public Dictionary<string, List<City>> infoConvoys
      {
         get { return convoys_; }
      }

      //////////////////////////////////////////////////////////////////////////
      //
      private static Logger logger_ = new Logger(typeof(Main));
      private World world_;
      private Dictionary<City, WorldInfoCity> cities_ = new Dictionary<City, WorldInfoCity>();
      private Dictionary<string, List<City>> convoys_ = new Dictionary<string, List<City>>();
   }
}
